package be.nvlooy.moviereminder.entities;

import javax.persistence.*;

@NamedQueries({
	@NamedQuery(name="Friendship.getByUserWithStatus",
			query="SELECT f FROM Friendship AS f WHERE f.user = :user AND f.status = :status"),

	@NamedQuery(name="Friendship.getIncomingRequests",
			query="SELECT f FROM Friendship AS f " +
					"WHERE f.friend = :user AND f.status = 'PENDING'"),

	@NamedQuery(name="Friendship.getOutgoingRequests",
			query="SELECT f FROM Friendship AS f " +
					"WHERE f.user = :user AND f.status = 'PENDING'"),

	@NamedQuery(name="Friendship.getByUserAndFriend",
			query="SELECT f FROM Friendship AS f WHERE f.user = :user AND f.friend = :friend")	,

	@NamedQuery(name="Friendship.findByName",
			query="SELECT fs FROM Friendship AS fs " +
					"JOIN fs.friend AS f " +
					"WHERE fs.user = :user AND LOWER(CONCAT(f.firstName, ' ', f.name)) LIKE LOWER(:search) " +
					"AND fs.status = :status")
})
@Entity
@Table(name="mrm_friendship", uniqueConstraints=@UniqueConstraint(columnNames={"user_id", "friend_id"}))
public class Friendship extends BaseEntity {
	
	@Id
	@GeneratedValue
    @Column(name="friendship_id")
	private long id;
	
	@ManyToOne
    @JoinColumn(name="user_id")
	private User user;

	@ManyToOne
    @JoinColumn(name="friend_id")
	private User friend;
	
	@Enumerated(EnumType.STRING)
	private FriendshipStatus status;

	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public User getFriend() {
		return friend;
	}

	public void setFriend(User friend) {
		this.friend = friend;
	}

	public FriendshipStatus getStatus() {
		return status;
	}

	public void setStatus(FriendshipStatus friendshipStatus) {
		this.status = friendshipStatus;
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getId() {
		return id;
	}
}
